package com.demo1.maven_plugin_demo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.junit.runners.Parameterized.Parameter;

@Mojo(name="gupaodemo",defaultPhase= LifecyclePhase.PACKAGE)
public class MojoDemo extends AbstractMojo{
	
	@Parameter
	private String dirPath;

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		List<Integer> is = new ArrayList<Integer>();

		System.out.println("dirPath    "+dirPath);
		File file = new File(dirPath);
		File[] list =  file.listFiles();
		int a = 0;
		for(File f : list){
			calCount(f,is);
		}
		System.out.println("===============================");
		System.out.println("项目中含有。java 文件数量：      "+is.size());
		System.out.println("===============================");
		
	}
	
	public static void main(String[] args) {
		String dirPath = "E:\\workspace\\testjar\\you";
		System.out.println("dirPath    "+dirPath);
		File file = new File(dirPath);
		File[] list =  file.listFiles();
		List<Integer> is = new ArrayList<Integer>();
		for(File f : list){
			calCount(f,is);
		}
		System.out.println("===============================");
		System.out.println("项目中含有。java 文件数量：      "+is.size());
		System.out.println("===============================");
	}
	
	private static void calCount(File file,List<Integer> list){
		//System.out.println(file.getName());
		if(file != null){
			if(file.isFile() && file.getName().indexOf(".java") != -1){
				list.add(1);
			}else if(file.isDirectory()){
				File[] files =  file.listFiles();
				if(files != null && files.length > 0){
					for(File f:files){
						calCount(f,list);
					}
				}
			}
		}
		
	}
	
}
